﻿package mortal.game.view.battle
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class BattleIcon extends HintBaseIcon
    {
        private var _battleApply:SBattleApply;
        private static var _instance:BattleIcon;

        public function BattleIcon(param1:String)
        {
            super(param1);
            if (_instance)
            {
                throw new Error("BattleIcon 单例");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.configEventListener(MouseEvent.CLICK, this.onClickBattleIcon);
            return;
        }// end function

        private function onClickBattleIcon(event:MouseEvent) : void
        {
            if (this._battleApply)
            {
                Alert.show(Language.getStringByParam(11208, this._battleApply.playerInfo.name), null, Alert.OK | Alert.CANCEL, null, this.onCloseAlert);
            }
            this.hide();
            return;
        }// end function

        private function onCloseAlert(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                CopyUtil.copyCheck(this.battleReplyOK);
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BattleReply, new BattleReplyObj(this._battleApply.playerInfo.entityId, false)));
            }
            return;
        }// end function

        protected function battleReplyOK() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BattleReply, new BattleReplyObj(this._battleApply.playerInfo.entityId, true)));
            return;
        }// end function

        public function updateApplyInfo(param1:SBattleApply) : void
        {
            this._battleApply = param1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : BattleIcon
        {
            if (!_instance)
            {
                _instance = new BattleIcon(ImagesConst.BattleIcon);
            }
            return _instance;
        }// end function

    }
}
